package collection;

import java.util.ArrayList;
import java.util.Collection;
/**
 * 集合保存引用类型元素，并且保存的是元素的引用(地址)
 */
public class CollectionDemo4 {
    public static void main(String[] args) {
        //泛型
        /*
        Collection<Point> c = new ArrayList<>();
        Point p = new Point(1, 2);
        c.add(p);//本质是将p变量保存的地址存入到集合中
        System.out.println("p:"+p);
        System.out.println("c:"+c);

        p.setX(2);//修稿p的x的值
        System.out.println("p:"+p);
        System.out.println("c:"+c);//集合也能看到修改p的效果

         */
        Collection<Point> c = new ArrayList<>();
        Point p = new Point(333, 66006);
        dosome(c,p);
        System.out.println("c:"+c);
        System.out.println("p:"+p);
    }
    public static void dosome(Collection<Point> c,Point p){
        c.add(p);
        p.setX(2);
        p = new Point(1000, 2222);
        c = new ArrayList<>();
        c.add(p);
    }
}
